#include <bits/stdc++.h>
using namespace std;

class Solution
{
public:
    int main()
    {
        int n, m;
        cin >> n >> m;
        int mSum = 0;
        int hurt = 0;
        vector<int> hurts(m);
        for (int i = 0; i < m; ++i)
        {
            cin >> hurt;
            hurts[i] = hurt;
            mSum += hurt;
        }
        int minMSum = mSum;
        for (int i = m; i < n; ++i)
        {
            cin >> hurt;
            mSum -= hurts[i % m];
            mSum += hurt;
            hurts[i % m] = hurt;
            minMSum = min(minMSum, mSum);
        }
        cout << minMSum;
        return 0;
    }
};

#ifndef __LOCAL_TEST__
int main()
{
    return Solution().main();
}
#endif